<?php
namespace app\admin\model\operating;
use think\facade\Db;
use app\admin\common;

class Ad{
	private $table_obj;
	public function selectAll($_where,$_field='*',$_order="id desc",$_limit){
		extract(common::get('ad',[$_where,$_field,$_order,__function__]));
		if(empty($data)){
			$_data=Db::name("ad")
						->where($_where)
						->field($_field)
						->order($_order)
						->limit(reset($_limit),end($_limit))
						->select();
			if(empty($_data)){
				return [];
			}
			$data=$_data->toArray();
			common::set($data);
		}
		return $data;
	}
	
	public function selectAllCount($_where,$_field){
		extract(common::get('ad',[$_where,$_field,__function__]));
		if(empty($data)){
			$data=Db::name("ad")
					
					->where($_where)
					->field($_field)
					->find();
			common::set($data);
		}
		return $data;
	}
	
	public function insertAd ($_data) 
	{
		$this->deleteCache('ad');
		return Db::name('ad')->strict(false)->insert($_data);
	}
	
	public function upAd($_up,$_where)
	{
		$this->deleteCache('ad');
		return Db::name('ad')->where($_where)->update($_up);
	}
	
	public function findDetails ($_where,$_field)
	{
		extract(common::get('ad',[$_where,$_field,__function__]));
		if(empty($data)){
			$data=Db::name("ad")->where($_where)->field($_field)->find();
			if(empty($data)){
				return [];
			}
			common::set($data);
		}
		return $data;
	}
	
	/**
	 * @Purpose 删除缓存
	 */
	private function deleteCache($str){
		common::delete($str);	
	}
	public function getLastSql(){
		return Db::getLastSql();
	}
	

}
?>